<template>
  <div>
    <h3>组合api - vuex</h3>
    <p>{{ count }}</p>
    <button @click="fn">btn</button>
  </div>
</template>

<script>
// useStore方法执行返回store实例
// 也要写在setup的顶层

// setup里面，没法使用辅助函数了
import { useStore } from "vuex";
import { computed } from "vue";
export default {
  setup() {
    const store = useStore();

    // const count = computed(() => {
    //   return store.state.count;
    // });

    // const fn = () => {
    //   store.commit("add");
    // };

    return {
      count: computed(() => {
        return store.state.count;
      }),
      fn: () => {
        store.commit("add");
      },
    };
  },
};
</script>
